package com.ruoyi.Students.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tutors.domain.Tutors;
import com.ruoyi.tutors.mapper.TutorsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.Students.mapper.StudentsMapper;
import com.ruoyi.Students.domain.Students;
import com.ruoyi.Students.service.IStudentsService;

/**
 * 学生信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-19
 */
@Service
public class StudentsServiceImpl extends ServiceImpl<StudentsMapper,Students> implements IStudentsService
{
    @Autowired
    private StudentsMapper studentsMapper;

    @Autowired
    private TutorsMapper tutorsMapper;

    /**
     * 查询学生信息
     * 
     * @param studentId 学生信息主键
     * @return 学生信息
     */
    @Override
    public Students selectStudentsByStudentId(Long studentId)
    {
        Students students = studentsMapper.selectStudentsByStudentId(studentId);
        students.setTutorsName(tutorsMapper.selectTutorsByTutorId(students.getTutorId()).getTutorName());
        return students;
    }

    /**
     * 查询学生信息列表
     * 
     * @param students 学生信息
     * @return 学生信息
     */
    @Override
    public List<Students> selectStudentsList(Students students)
    {
        List<Students> list = studentsMapper.selectStudentsList(students);

        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getTutorId() != null){
                list.get(i).setTutorsName(tutorsMapper.selectTutorsByTutorId(list.get(i).getTutorId()).getTutorName());
            }

        }


        return list;
    }

    /**
     * 新增学生信息
     * 
     * @param students 学生信息
     * @return 结果
     */
    @Override
    public int insertStudents(Students students)
    {
        return studentsMapper.insertStudents(students);
    }

    /**
     * 修改学生信息
     * 
     * @param students 学生信息
     * @return 结果
     */
    @Override
    public int updateStudents(Students students)
    {
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("tutor_name",students.getTutorsName());
//        students.setTutorId(tutorsMapper.selectTutorsByTutorName(students.getTutorsName()).getTutorId());
        return studentsMapper.updateStudents(students);
    }

    /**
     * 批量删除学生信息
     * 
     * @param studentIds 需要删除的学生信息主键
     * @return 结果
     */
    @Override
    public int deleteStudentsByStudentIds(Long[] studentIds)
    {
        return studentsMapper.deleteStudentsByStudentIds(studentIds);
    }

    /**
     * 删除学生信息信息
     * 
     * @param studentId 学生信息主键
     * @return 结果
     */
    @Override
    public int deleteStudentsByStudentId(Long studentId)
    {
        return studentsMapper.deleteStudentsByStudentId(studentId);
    }
}
